<?php

$images_url = base_url('images');
$main_url = base_url('main');

$mapdir = "
	<a href='$main_url'>Home</a>
	&gt; 
	<b>Produk</b>
";

$awal = $this->uri->segment(3,0);
$order = $this->input->get('order');
$total_rows = 0;
$suffix = "";
$first_url = "";
$daftarkategori = "";
$dataproduk = "";
$judul = "";

$kategori = $this->mainmodel->get_daftar_kategori();
if($kategori !== FALSE)
{
	$jumkat = $kategori->num_rows();
	$tengah = ceil($jumkat/2);
	$kathit = 1;
	$katkanan = "";
	$katkiri = "";
	
	foreach($kategori->result() AS $cat)
	{
		
		if($kathit <= $tengah)
		{
			$katkanan .= "<a href='$main_url/produk.html?order=cat&amp;kat=$cat->idkategori'>$cat->kategori</a> <br />";
		}
		else
		{
			$katkiri .= "<a href='$main_url/produk.html?order=cat&amp;kat=$cat->idkategori'>$cat->kategori</a> <br />";
		}
		$kathit++;
	}
	
	$daftarkategori = "
		<div id='kategori'>
			<div class='left'>$katkanan</div>
			<div class='right'>$katkiri</div>
		</div>
	";
}

switch ($order)
{
	case "asc":
		$judul = "<h5>Produk Berdasarkan data Terlama</h5>";
		$produk = $this->mainmodel->get_daftar_produk($awal, 'asc');
		$total_rows = $this->mainmodel->hitung_data('idproduk','dn_product');
		$first_url = base_url('main/produk.html?order='.$order);
		$suffix = '/list.html?order='.$order;
	;
	break;
	
	case "abja":
		$judul = "<h5>Produk Berdasarkan Abjad A-Z </h5>";
		$produk = $this->mainmodel->get_daftar_produk_abj($awal, 'asc');
		$total_rows = $this->mainmodel->hitung_data('idproduk','dn_product');
		$first_url = base_url('main/produk.html?order='.$order);
		$suffix = '/list.html?order='.$order;
	;
	break;
	
	case "abjz":
		$judul = "<h5>Produk Berdasarkan data Abjad Z-A </h5>";
		$produk = $this->mainmodel->get_daftar_produk_abj($awal, 'desc');
		$total_rows = $this->mainmodel->hitung_data('idproduk','dn_product');
		$first_url = base_url('main/produk.html?order='.$order);
		$suffix = '/list.html?order='.$order;
	;
	break;
	
	case "usaha":
		$idc = $this->input->get('id');
		$judul = "<h5>Produk dari Perusahaan <b style='color:#b70bac'>".$this->mainmodel->get_single_data('nama','dn_company','idperusahaan',$idc)."</b></h5>";
		$produk = $this->mainmodel->get_produk_usaha($awal, $idc);
		
		$first_url = base_url('main/produk.html?order='.$order.'&id='.$idc);
		$suffix = '/list.html?order='.$order.'&id='.$idc;
		$total_rows = $this->mainmodel->get_hitung_produk_usaha($idc);
		
	;
	break;
	
	case "cat":
		$kat = $this->input->get('kat');
		$judul = "<h5>Produk dengan kategori <b style='color:#b70bac'>".$this->mainmodel->get_single_data('kategori','dn_category','idkategori',$kat)."</b></h5>";
		$produk = $this->mainmodel->get_daftar_produk_kategori($awal, $kat);
		
		$first_url = base_url('main/produk.html?order='.$order.'&kat='.$kat);
		$suffix = '/list.html?order='.$order.'&kat='.$kat;
		$total_rows = $this->mainmodel->get_hitung_produk_kategori($kat);
	;
	break;
	
	default:
		$judul = "<h5>Produk Berdasarkan data Terbaru</h5>";
		$produk = $this->mainmodel->get_daftar_produk($awal, 'desc');
		$total_rows = $this->mainmodel->hitung_data('idproduk','dn_product');
		$first_url = base_url('main/produk.html?order='.$order);
		$suffix = '/list.html?order='.$order;
	;
	break;
}

try{
	$hit = $awal+1;
}catch (Exception $e){
	$hit = 1;
}

if($produk !== FALSE)
{
	foreach($produk AS $pdata)
	{
		$title = url_title($pdata->nama, '-', TRUE);
		
		if($hit % 2 == 0)
		{
			$warna = "bgputih";
		}
		else
		{
			$warna = "bgbiru";
		}
		
		$dataproduk .= "
		<tr class='$warna'>
			<td class='left'>$hit. <a href='$main_url/detail/$pdata->idproduk/produk/$title.html'>$pdata->nama</a></td>
			<td class='right'><a href='$main_url/detail/$pdata->idproduk/produk/$title.html'>Detail</a> </td>
		</tr>";
		$hit++;
	}
}
else
{
	$dataproduk .= "
	<tr>
		<td class='left'>&nbsp;</td><td class='right'>Data Belum Tersedia</td>
	</tr>";
}

$config['base_url'] = base_url('main/produk');
$config['total_rows'] = $total_rows;
$config['per_page'] = 20; 
$config['first_url'] = $first_url; 
$config['suffix'] = $suffix;

$this->pagination->initialize($config); 		
$halaman = $this->pagination->create_links();

$isipage = "
	<div id='content2'>
			<h3>Daftar Produk</h3>
				
				
				<div class='isicontent2'>
				  <p>
					 Urutan berdasarkan : <a href='$main_url/produk.html?order=desc'>Terbaru</a> | <a href='$main_url/produk.html?order=asc'>Terlama</a> | <a href='$main_url/produk.html?order=abja'>Abjad A-Z</a> | <a href='$main_url/produk.html?order=abjz'>Abjad Z-A</a> 
				  </p>
				</div>
				
				<div class='isicontent2'>
				  <p>
					 Produk berdasarkan Kategori : 
				  </p>
				  
				  $daftarkategori
				  
				  <br />
				  <div class='blank'></div>
				</div>
				
				<div class='isicontent2'>
					<div id='produk'>
					$judul
					<table>
						<tbody>
							
							$dataproduk
								
							<tr>
								<td class='left'>&nbsp;</td>
								<td class='right'>$halaman</td>
							</tr>
						</tbody>
					</table>
					</div>
				</div>
				
			</div>
";

$data['map_dir'] = $mapdir;
$data['isi_page'] = $isipage;
$data['site_title'] = 'Daftar Produk - Dadan Network';
$data['site_description'] = 'Dadan Network adalah situs berbagi informasi tentang jaringan profesional antar enterpreneur indonesia';
$data['site_keywords'] = 'dadan, network, profesional, enterpreneur, produk, usaha';
$data['base_url'] = base_url();
$data['tahun_sekarang'] = date("Y");
$data['other_head'] = '';

$this->parser->parse('template/home', $data);

/* End of file produk.php */
/* Location: ./application/views/main/produk.php */
